package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.RD;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.dto.ElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceDataGraphVo;
import com.zzyl.nursing.vo.DeviceDateVo;
import com.zzyl.nursing.vo.LoginVo;
import com.zzyl.nursing.vo.PropertyStatusInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalTime;
import java.util.List;
import java.util.Map;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto){
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    /**
     * 查询健康数据
     * @param deviceDto
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询健康数据")
    public AjaxResult findHealthData(@RequestBody DeviceDto deviceDto){
        AjaxResult result = familyMemberService.findHealthData(deviceDto);
        return result;
    }

    /**
     * 绑定家人
     * @param elderDto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult insertFamily(@RequestBody ElderDto elderDto){
        AjaxResult result = familyMemberService.insertFamily(elderDto);
        return result;
    }

    /**
     * 查询家人列表
     * @return
     */
    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult findMyFamily(){
        AjaxResult result = familyMemberService.findMyFamily();
        return result;
    }

    /**
     * 查看家人列表（分页查询）
     * @return
     */
    @GetMapping("/list-by-page")
    @ApiOperation("查看家人列表（分页查询）")
    public AjaxResult pageFamily(Integer pageNum, Integer pageSize  ){
        AjaxResult result = familyMemberService.pageFamily(pageNum,pageSize);
        return result;
    }

    @DeleteMapping("/deleteById")
    public AjaxResult deleteByMId(Long id){
        AjaxResult result = familyMemberService.deleteByMId(id);
        return result;
    }
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按日查询设备数据")
    public R<List<DeviceDataGraphVo>> queryDeviceDataListByDay(
            @ApiParam(value = "物联网设备id") @RequestParam("iotId") String iotId,
            @ApiParam(value = "功能ID") @RequestParam("functionId") String functionId,
            @ApiParam(value = "开始时间，传入指定日期的0点对应时间戳") @RequestParam("startTime") Long startTime,
            @ApiParam(value = "结束时间，传入指定日期的23:59:59对应时间戳") @RequestParam("endTime") Long endTime) {
        List<DeviceDataGraphVo> deviceDataGraphVos = familyMemberService.queryDeviceDataListByDay(iotId, functionId, startTime, endTime);
        return R.ok(deviceDataGraphVos);
    }

    @GetMapping("/queryDeviceDataListByWeek")
    public R<List<DeviceDataGraphVo>> queryDeviceDataListByWeek(@ApiParam(value = "物联网设备id") @RequestParam("iotId") String iotId,
                                                                @ApiParam(value = "功能ID") @RequestParam("functionId") String functionId,
                                                                @ApiParam(value = "开始时间，传入指定日期的0点对应时间戳") @RequestParam("startTime") Long startTime,
                                                                @ApiParam(value = "结束时间，传入指定日期的23:59:59对应时间戳") @RequestParam("endTime") Long endTime) {
        List<DeviceDataGraphVo> deviceDataGraphVos =familyMemberService.queryDeviceDataListByWeek(iotId, functionId, startTime, endTime);
        return R.ok(deviceDataGraphVos);
    }
}
